package com.ruoyi.web.controller.ydz;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.LeaveWord;
import com.ruoyi.web.service.ILeaveWordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言Controller
 * 
 * @author LFY
 * @date 2024-02-28
 */
@Controller
@RequestMapping({"/ydz/leaveWord","/api/leaveWord"})
@Api(tags = "留言")
public class LeaveWordController extends BaseController
{
    private String prefix = "ydz/leaveWord";

    @Autowired
    private ILeaveWordService leaveWordService;

    @RequiresPermissions("ydz:leaveWord_lc:view")
    @GetMapping("/lc")
    public String lcLeaveWord()
    {
        return prefix + "/lcLeaveWord";
    }

    @RequiresPermissions("ydz:leaveWord_ly:view")
    @GetMapping("/ly")
    public String lyLeaveWord()
    {
        return prefix + "/lyLeaveWord";
    }

    @RequiresPermissions("ydz:leaveWord_tel:view")
    @GetMapping("/tel")
    public String TelLeaveWord()
    {
        return prefix + "/telLeaveWord";
    }

    /**
     * 查询留言列表
     */
    @RequiresPermissions("ydz:leaveWord:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询留言列表")
    public TableDataInfo list(LeaveWord leaveWord)
    {
        startPage();
        List<LeaveWord> list = leaveWordService.selectLeaveWordList(leaveWord);
        return getDataTable(list);
    }

    /**
     * 导出留言列表
     */
    @RequiresPermissions("ydz:leaveWord:export")
    @Log(title = "留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出留言列表")
    public AjaxResult export(LeaveWord leaveWord)
    {
        List<LeaveWord> list = leaveWordService.selectLeaveWordList(leaveWord);
        ExcelUtil<LeaveWord> util = new ExcelUtil<LeaveWord>(LeaveWord.class);
        return util.exportExcel(list, "留言数据");
    }

    /**
     * 新增留言
     */
    @GetMapping("/add")
    @ApiOperation("新增留言")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存留言
     */
    @ApiOperation("新增保存留言")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LeaveWord leaveWord)
    {
        return leaveWordService.insertLeaveWord(leaveWord);
    }

    /**
     * 新增保存留言
     */
    @ApiOperation("新增保存留言")
    @Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping("/addLeaveWord")
    @ResponseBody
    public AjaxResult addLeaveWord(@RequestBody LeaveWord leaveWord)
    {
        return leaveWordService.insertLeaveWord(leaveWord);
    }

    /**
     * 修改留言
     */
    @ApiOperation("修改留言")
    @RequiresPermissions("ydz:leaveWord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LeaveWord leaveWord = leaveWordService.selectLeaveWordById(id);
        mmap.put("leaveWord", leaveWord);
        return prefix + "/edit";
    }

    /**
     * 修改保存留言
     */
    @ApiOperation("修改保存留言")
    @RequiresPermissions("ydz:leaveWord:edit")
    @Log(title = "留言", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LeaveWord leaveWord)
    {
        return toAjax(leaveWordService.updateLeaveWord(leaveWord));
    }

    /**
     * 删除留言
     */
    @ApiOperation("删除留言")
    @RequiresPermissions("ydz:leaveWord:remove")
    @Log(title = "留言", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(leaveWordService.deleteLeaveWordByIds(ids));
    }
}
